package com.company;



import java.util.ArrayList;
import java.util.List;


/**
 * @author 输出1~20000内的所有素数，按每行5个打印出来
 */
public class test3 {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        int sum = 0;
        for (int i = 2; i <= 20000; i++) {
            boolean flag = true;
            for(int j = 2; j< Math.sqrt(i); j++){
                if(i % j == 0){
                    flag = false;
                    break;
                }
            }
            if(flag){
                sum++;
                list.add(i);
                if(list.size() % 5 == 0){
                    for (Integer integer : list) {
                        System.out.print(integer+"\t");
                    }
                    System.out.println("");
                    list.clear();
                }
            }
        }
        System.out.println("1-20000的素数个数: " + sum);
    }

}
